
var toppages=1;
function toppage()
{
	var count1=document.getElementById("hidecount1").value;
	toppages=toppages-1;
	if(toppages==0)
		{
		toppages=toppages+1;
		document.getElementById("pagetext").value=toppages;
		getpage(toppages,count1);
		}
	else{
		getpage(toppages,count1);
		document.getElementById("pagetext").value=toppages;
	}
}
function nextpage()
{
	var count1=document.getElementById("hidecount1").value;
	var count=document.getElementById("hidecount").value;
	if(parseInt(toppages)>=parseInt(count))
		{
		nextpages=parseInt(count);
		}
	else{
	nextpages=toppages+1;
	}
	document.getElementById("pagetext").value=nextpages;
	getpage(nextpages,count1);
	toppages=nextpages;
}
function searchpage()
{
	var count1=document.getElementById("hidecount1").value;
	var count=document.getElementById("hidecount").value;
	var page=document.getElementById("pagetext").value;
	if(page=="")
		{
		}
	else{
	if(parseInt(page)>parseInt(count))
		{
		page=count;
		}
	getpage(page,count1);
	document.getElementById("pagetext").value=page;
	}
	}
function register_close()
{
	$(".register").css("display", "none");
	var count1=document.getElementById("hidecount1").value;
	getpage(toppages,count1);
	}
function register()
{
	$(".register").css("display", "block");
	}
function login_close()
{

	$(".login").css("display", "none");
	var count1=document.getElementById("hidecount1").value;
	getpage(toppages,count1);

	}
function login()
{
	var delu=document.getElementById("delu").innerHTML;
	if(delu=="您好，请登录")
		{
	$(".login").css("display", "block");
		}
	else
		{
		getInfo(delu);
		}
	}
/*function delu()
{
	var s=document.getElementById("userName").innerHTML;
	alert(s);
	getpage(1,2);
	}*/
function getpage(toppages,typeID)
{	
$("#food_from").empty();
$.ajax(
		{
			type:"post",
			url:"/currentPageAjax",
			dateType:"json",
			data : {
				"pagecount":toppages,
				"typeID":typeID,
			},
			success:function(data,textStatus){
				if(data==null)
					{
					alert("空");
					}
				else{
					for (var i = 0; i < data.length; i++) {
						var newTag="<div class='food_from_1'><div id='food_pro1' class='food_pro'><div id='food_image1' class='food_image' style='background-image:url("+data[i].productPhoto+");'></div><div id='food_name1' class='food_name'><a>"+data[i].productName+"</a></div></div><div id='food_price1' class='food_price'><font color=red>￥"+data[i].productPrice+".00/件</font></div></div>";
						$("#food_from").append(newTag);	
					}
				}
				
			},
			error : function(xhr, status, error) {
				alert(error);
			}
		})
}
function getInfo(username)
{	
$.ajax(
		{
			type:"post",
			url:"/userInfoAjax",
			dateType:"json",
			data : {
				"username":username,
			},
			success:function(data,textStatus){
				if(data==null)
					{
					alert("空");
					}
				else{
					window.location.href = "/userInfo";
				}
				
			},
			error : function(xhr, status, error) {
				alert(error);
			}
		})
}


function reg()
{
	var username=document.getElementById("username").value;
	var userpass=document.getElementById("userpass").value;
	var usersex=document.getElementById("usersex").value;
	var usercard=document.getElementById("usercard").value;
	var userage=document.getElementById("userage").value;
	var useradress=document.getElementById("useraddress").value;
	var useremil=document.getElementById("useremil").value;
	var userphone=document.getElementById("userphone").value;
	getInsertInfo(username,userpass,usersex,usercard,userage/*,useradress,useremil,userphone*/);
	alert(userpass);
	}
function getInsertInfo(username,userpass,usersex,usercard,userage/*,useradress,useremil,userphone*/)
{	
$.ajax(
		{
			type:"post",
			url:"/userInsertInfoAjax",
			dateType:"json",
			data : {
				"username":username,
				"userpass":userpass,
				"usersex":usersex,
				"usercard":usercard,
				"userage":userage,
				/*"useradress":useradress,
				"useremil":useremil,
				"userphone":userphone,*/
			},
			success:function(data,textStatus){
				if(data==null)
					{
					alert("空");
					}
				else{
					window.location.href = "/userInsertInfo";
				}
				
			},
			error : function(xhr, status, error) {
				alert(error);
			}
		})
}